package com.wu.mp.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wu.mp.common.JsonResult;
import com.wu.mp.common.Responses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * className: GlobalExceptionInterceptionConfig <br/>
 * author: xwu36 <br/>
 * date: 2019/7/2 15:15 <br/>
 * describe: 全局异常捕获类
 *
 * @author xwu36
 */

@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionInterceptionConfig {
    ObjectMapper mapper = new ObjectMapper();

    @ExceptionHandler(value = Exception.class)
    public JsonResult exceptionHandle(HttpServletRequest request, HttpServletResponse response, Exception e) throws JsonProcessingException {

        return Responses.error();
    }
}
